* ============================================================================ *
* PROJECT:		US Study 1 PRIMARY ELECTIONS
* OBJECTIVE: 	Analyses for paper "Do people want smarter ballots?"
* AUTHOR: 		Semra Sevi, André Blais and Carolina Plescia  
* DATE:			2020-06-26
* ============================================================================ *

*Use dataset 
use "US_Study1.dta", clear

*------------------------------------------------------------------------------*
*MODELS
*------------------------------------------------------------------------------*

*Appendix C.1
eststo clear
local quad age_std edu_std ib2.gender i.state_num party_id ib4.race ///
	ideology_std experience_ranked 
eststo m5: reg single_norm `quad'
eststo m6: reg rank_norm `quad'
eststo m7: reg approval_norm `quad'
eststo m8: reg point_norm `quad'

esttab m5 m6 m7 m8 using quad_study1_separately.rtf, ///
	drop(*state_num*) replace b(3) se(3) ///
	stats(r2 N Fixed_State, fmt(%9.3f)) nogap label compress 
	
*Figure 3: Normalized evaluations of the single vote
coefplot (m5, keep(age_std edu_std)), xline(0) p1(label(Single)) ///
	coeflabels(age_std = "Age" edu_std = "Education", ///
	labsize(medlarge)) xscale(range(-.5 2.5)) ///
	xtitle(Study 1, size(medlarge)) xlabel(-.5(.5)2.5, labsize(medlarge))

*Appendix C.2
eststo clear
local quad age_std edu_std interest_politics ib2.gender i.state_num party_id ib4.race ///
	ideology_std experience_ranked
eststo m1: reg single_norm `quad'
eststo m2: reg rank_norm `quad'
eststo m3: reg approval_norm `quad'
eststo m4: reg point_norm `quad'	

esttab m1 m2 m3 m4 using quad_study1_appendix_interest.rtf, ///
	drop(*state_num*) replace b(3) se(3) ///
	stats(r2 N Fixed_State, fmt(%9.3f)) nogap label compress 

*Appendix D 
eststo clear
local quad age_std edu_std ib2.gender i.state_num party_id ib4.race ideology_std experience_ranked
eststo m1: mlogit preference `quad'

esttab m1 using mlogit_1.rtf, ///
	drop(*state_num*) replace b(3) se(3) ///
	stats(r2 N Fixed_State, fmt(%9.3f)) nogap label compress 	

	
*Creating first, second, third and last voting systems respondents saw
gen first_system = floor(rand_votingscenariosN/1000)	
gen second_system = floor((rand_votingscenariosN - first_system*1000)/100)	
gen third_system = floor((rand_votingscenariosN - first_system*1000 - second_system*100)/10)	
gen last_system = mod(rand_votingscenariosN, 10)	
	
*Order variables for fixed effects
gen single_order = 1 if first_system == 1
replace single_order = 2 if second_system == 1
replace single_order = 3 if third_system == 1
replace single_order = 4 if last_system == 1
	
gen rank_order = 1 if first_system == 2
replace rank_order = 2 if second_system == 2
replace rank_order = 3 if third_system == 2
replace rank_order = 4 if last_system == 2

gen point_order = 1 if first_system == 3
replace point_order = 2 if second_system == 3
replace point_order = 3 if third_system == 3
replace point_order = 4 if last_system == 3

gen approval_order = 1 if first_system == 4
replace approval_order = 2 if second_system == 4
replace approval_order = 3 if third_system == 4
replace approval_order = 4 if last_system == 4	


*Appendix E Main models with candidates as control
eststo clear
local quad age_std edu_std ib2.gender i.state_num party_id ib4.race ///
ideology_std experience_ranked biden bloomberg buttigieg klobuchar sanders warren
eststo m5: reg single_norm `quad'
eststo m6: reg rank_norm `quad'
eststo m7: reg approval_norm `quad'
eststo m8: reg point_norm `quad'

esttab m5 m6 m7 m8 using quad_study1_candidates.rtf, ///
	drop(*state_num*) replace b(3) se(3) ///
	stats(r2 N Fixed_State, fmt(%9.3f)) nogap label compress 

*Appendix F Main models with order fixed effects
eststo clear
local quad age_std edu_std ib2.gender i.state_num party_id ib4.race ideology_std experience_ranked
eststo m1: reg single_norm `quad' i.single_order
eststo m2: reg rank_norm `quad' i.rank_order
eststo m3: reg approval_norm `quad' i.approval_order
eststo m4: reg point_norm `quad' i.point_order

esttab m1 m2 m3 m4 using main_models_study1_order.rtf, ///
	drop(*state_num*) replace b(3) se(3) ///
	stats(r2 N Fixed_State, fmt(%9.3f)) nogap label compress
**_order

*Appendix G first system respondent chooses to see 
eststo clear
local quad age_std edu_std ib2.gender i.state_num party_id ib4.race ideology_std experience_ranked
eststo m1: reg single_norm `quad' if first_system ==1
eststo m2: reg rank_norm `quad' if first_system ==2
eststo m3: reg approval_norm `quad' if first_system ==4
eststo m4: reg point_norm `quad' if first_system ==3
	
esttab m1 m2 m3 m4 using first_separate_normalized.rtf, ///
	drop(*state_num*) replace b(3) se(3) ///
	stats(r2 N Fixed_State, fmt(%9.3f)) nogap label compress

*Appendix H: Interactions Party and Age
eststo clear
local quad edu_std ib2.gender i.state_num c.party_id##c.age_std ib4.race ///
	ideology_std experience_ranked 
eststo m5: reg single_norm `quad'
eststo m6: reg rank_norm `quad'
eststo m7: reg approval_norm `quad'
eststo m8: reg point_norm `quad'

esttab m5 m6 m7 m8 using quad_study1_partyXage.rtf, ///
	drop(*state_num*) replace b(3) se(3) ///
	stats(r2 N Fixed_State, fmt(%9.3f)) nogap label compress 
	
*Appendix H: Interactions Rank Vote Experience and Party
local quad age_std edu_std ib2.gender i.state_num c.party_id##i.experience_ranked ib4.race ///
	ideology_std 
eststo m5: reg single_norm `quad'
eststo m6: reg rank_norm `quad'
eststo m7: reg approval_norm `quad'
eststo m8: reg point_norm `quad'
 
esttab m5 m6 m7 m8 using quad_study1_partyXexperience.rtf, ///
	drop(*state_num*) replace b(3) se(3) ///
	stats(r2 N Fixed_State, fmt(%9.3f)) nogap label compress 	


*------------------------------------------------------------------------------*
*FIGURES 
*------------------------------------------------------------------------------*
	
su Q17_single Q17_approval Q17_rank Q17_point if Q13 == 3
su single_norm approval_norm rank_norm point_norm if Q13 == 3

*39 and below
su single_norm approval_norm rank_norm point_norm if Q13 == 3 & age<= 39
*40 and above 
su single_norm approval_norm rank_norm point_norm if Q13 == 3 & age>= 40

*ever personally voted with a ranked ballot
*39 and below
tab preference if Q13 == 3 & age<= 39
*40 and above 
tab preference if Q13 == 3 & age>= 40	
	
* ttest for significance among the ratings 
ttest single_norm == approval_norm if Q13 == 3
ttest single_norm == rank_norm if Q13 == 3
ttest single_norm == point_norm if Q13 == 3
ttest approval_norm == rank_norm if Q13 == 3
ttest approval_norm == point_norm if Q13 == 3
ttest rank_norm == point_norm if Q13 == 3

* Have you ever heard of ranked ballot
tab preference if Q11 == 2

*distribution of two variables we collapse to create preference
su Q19A Q19B

*Figure 1: bar plot with 95% CI:
preserve
rename single_norm satisfaction1 
rename approval_norm satisfaction2  
rename rank_norm satisfaction3
rename point_norm satisfaction4	
gen obs = _n 
reshape long satisfaction, i(obs) j(votesystem)
*STEP 1:
/*keep only the variables you need*/
keep satisfaction obs votesystem
*STEP 2:
/*collapse the data by voting system*/
collapse (mean) meansatisfaction=satisfaction (semean) semeansatisfaction=satisfaction, by(votesystem)
*STEP 3:
/*generate 95% CI*/
gen _ci_lb= meansatisfaction-1.96*semeansatisfaction
gen _ci_ub= meansatisfaction+1.96*semeansatisfaction
*STEP 4:
/*generate plot*/
twoway (bar meansatisfaction votesystem if votesystem==1,  barw(.7) lp(solid) bcolor(black*0.7))  ///
	(bar meansatisfaction votesystem if votesystem==2, barw(.7) bcolor(black*0.7)) ///
	(bar meansatisfaction votesystem if votesystem==3, barw(.7) bcolor(black*0.7)) ///
	(bar meansatisfaction votesystem if votesystem==4, barw(.7) bcolor(black*0.7)) ///
       (rcap _ci_lb _ci_ub votesystem), legend(off) xlabel( 1 "single" 2 "approval" 3 "rank" 4 "point", labsize(medlarge))  ///
       ytitle("Satisfaction", size(large)) xtitle("Study 1", size(large)) graphregion(fcolor(gs15))yscale(range(0 4)) ///
	   ylabel(0(1)4, labsize(medlarge)) text(3.56 1 "3.36") text(2.44 2 "2.25") text(2.40 3 "2.19") text(2.40 4 "2.20") ///
	   graphregion(color(white)) bgcolor(white) 
restore 	
	
*Figure 2 for % of respondents who chose each voting system at the end
graph bar, over(preference, sort(1) descending label(labsize(medlarge))) ///
	bargap(30) yscale(range(0 80)) ylabel(0(20)80,labsize(medlarge)) ///
	b1title("Study 1", size(medlarge)) ytitle("Percent", size(large)) ///
	text(72 11 "67.95") text(19 37 "14.72") text(13 63 "8.66") text(13 89 "8.66")	
	
*gen variables which indicate the voting system they gave the highest rating to
egen max_rating = rowmax(Q17_single Q17_approval Q17_rank Q17_point)
gen Q17_single_max = (max_rating == Q17_single)
gen Q17_approval_max = (max_rating == Q17_approval)
gen Q17_rank_max = (max_rating == Q17_rank)
gen Q17_point_max = (max_rating == Q17_point)
gen Q17_max_num = Q17_single_max + Q17_approval_max + Q17_rank_max + Q17_point_max

*identify any respondents with ties for maximum satisfaction
gen highest_ties = 1 if Q17_max_num != 1
replace highest_ties = 0 if Q17_max_num == 1

*Appendix B
su age_std edu_std ib2.gender i.state_num party_id ib3.race
su biden warren sanders bloomberg buttigieg klobuchar

*Table 1
bysort age_groups: su single_norm approval_norm rank_norm point_norm 
*Q17_single Q17_approval Q17_rank Q17_point

*preference for easy by age group
bysort age_groups: su single_easy

*ranked voting is selected as best allowing expression of views 
tab rank_express if Q11 == 2

*percentage of respondents who voted with a ranked ballot before 
tab Q13, missing 

*preferences for different vote systems among those who voted with ranked ballot before
su Q17_single if Q13 == 3
su Q17_rank if Q13 == 3
su Q17_approval if Q13 == 3
su Q17_point if Q13 == 3

su single_norm if Q13 == 3
su rank_norm if Q13 == 3
su approval_norm if Q13 == 3
su point_norm if Q13 == 3

*Most of the ties involve single. 953 are single out of 1174 = 81%. 46% have ties 1174/2540
*In the ties that involve single 66% people choose single in the end.	
tab highest_ties Q17_single_max	
tab preference if highest_ties == 1 & Q17_single_max == 1


